﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Web.Security;


public partial class Registration : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
       
    }

    protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {

    }

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            mvRegistration.SetActiveView(mvViewProfile);
            Session[String.Format("{0}PSWSESSION",tbUserName.Text)] = Password.Text;
                        
        }
        
    }
    protected void btnCreateUser_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            if (!String.IsNullOrEmpty(tbUserName.Text) && !String.IsNullOrEmpty(Session[String.Format("{0}PSWSESSION", tbUserName.Text)].ToString()) && !String.IsNullOrEmpty(Email.Text))
            {
                try
                {
                    MembershipUser newMembershipUser = Membership.CreateUser(tbUserName.Text, Session[String.Format("{0}PSWSESSION", tbUserName.Text)].ToString(), Email.Text);
                    ProfileEntity profileEntity = ((UserControls_EditUserProfile)EditUserProfile2).GetProfileEntity();
                    ProfileManagement.SaveProfile(profileEntity, tbUserName.Text);
                    
                    //ProfileCommon p = (ProfileCommon)ProfileCommon.Create(tbUserName.Text);

                    //p.OwnAge = profileEntity.OwnAge;
                    //p.ExpectedAge = profileEntity.PartnerAge;
                    //p.ExpectedHighestSchool = profileEntity.PartnerHighestSchool;
                    //p.OwnHighestSchool = profileEntity.OwnHighestSchool;
                    //p.OwnBuild = profileEntity.OwnBuild;
                    //p.ExpectedBuild = profileEntity.PartnerBuild;
                    //p.Save();


                    mvRegistration.SetActiveView(mvViewSuccess);
                }
                catch (Exception)
                {
                    mvRegistration.SetActiveView(mvViewFailed);
                }
            }

        }
    }
}